<?php

require_once("classes/adrese.template.class.php");

function getAdresaHtml($lid , $tip, $identifikator="", $style="", $ul_type=1){
	
	//za $ID= -1 => rec je o novom polju
	//za $ID>=0 => rec je o ID-u postojeceg polja
	
	$new = ($lid==-1)? true:false;
	
	if(!isset($lid) && !$new){
		//die("No address id.");
	}elseif($new){
		$lid = NULL;
	}
	
	
	// instantinate class
	// param: int sifra_adrese
	$ul_template = new adrese_template($lid,$ul_type);
	
	
	if($new){
		// define html-object names (inputs, selects)
		$field_names = array(
		// naziv u tpl		=> naziv na strani
			"new_region"	=> "region".$identifikator,
			"new_opstina"	=> "opstina".$identifikator,
			"new_grad"		=> "grad".$identifikator,
			"new_lokopstina"=> "lok_opstina".$identifikator,
			"new_naselje"	=> "naselje".$identifikator,
			"new_ulica"		=> "ulica".$identifikator,
			"new_broj"		=> "broj".$identifikator
		);
		$ul_template->defineFieldNames($field_names);
		
		$ul_template->addNew();
		return $ul_template->template_html;
	}else{
		// define html-object names (inputs, selects)
		// ulica i broj
		$field_names = array(
		// naziv u tpl		=> naziv na strani
			"select_region"	=> "region".$identifikator,
			"select_opstina"	=> "opstina".$identifikator,
			"select_grad"		=> "grad".$identifikator,
			"select_lokopstina"=> "lok_opstina".$identifikator,
			"select_naselje"	=> "naselje".$identifikator,
			"txt_ulica"		=> "ulica".$identifikator,
			"txt_ulica_id"		=> "ulica_id".$identifikator,
			"txt_broj"		=> "broj".$identifikator
		);
		$ul_template->defineFieldNames($field_names);
		
		// parse desired type of template
		// param: string type
		// 	ulica i broj  => "ulica" 
		// 	naselje	 => "naselje"
		// 	lok.opst.	 => "lok_opstina"
		// 	grad	 => "grad"
		// 	opstina	 => "opstina"
		// 	region	 => "region"
		//	all	 => NULL
		$ul_template->parseIt($tip,$style);
		
		// retrieve code
		$html = $ul_template->template_html;
		
		return $html;
	}
}
?>